﻿using ASP;
using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public partial class Admin_Admin_ShopSaleView : Admin, IRequiresSessionState
{
    protected int UserID = 0;
    protected string wherestr = "";
    protected string linkhead = "";
    protected bool tag = true;
    private ArrayList al = new ArrayList();
    private IDbDataParameter[] param = null;
    private Shop_Order _shop_order = null;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Shop_Order shop_order
    {
        get
        {
            Shop_Order shop_order;
            if (this._shop_order == null)
            {
                this._shop_order = new Shop_Order(this.conn); 
                shop_order = this._shop_order;
            }
            else
            {
                shop_order = this._shop_order;
            }
            return shop_order;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(22))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Order");
            base.WriteRightErrMsg();
        }
        this.TxtBeginDate.Attributes.Add("onClick", string.Concat(new string[]
		{
			"show_cele_date(",
			this.TxtBeginDate.UniqueID,
			",'','',",
			this.TxtBeginDate.UniqueID,
			");"
		}));
        this.TxtEndDate.Attributes.Add("onClick", string.Concat(new string[]
		{
			"show_cele_date(",
			this.TxtEndDate.UniqueID,
			",'','',",
			this.TxtEndDate.UniqueID,
			");"
		}));
        if (!base.IsPostBack)
        {
            this.BindDate();
        }
    }
    protected void BindDate()
    {
        this.QueryString();
        if (this.al.Count > 0)
        {
            this.param = new IDbDataParameter[this.al.Count];
            this.al.CopyTo(this.param, 0);
        }
        this.GridView1.DataSource = this.shop_order.GetSaleOrder(this.wherestr, int.Parse(this.DropDownList1.SelectedValue), this.param);
        this.GridView1.DataBind();
    }
    protected void QueryString()
    {
        this.wherestr = "and ((TradeType=2 and Status=1) or (TradeType=3 and Status=1) or (TradeType<>2 and TradeType<>3)) ";
        string text = this.TxtBeginDate.Text;
        if (text != string.Empty)
        {
            if (!Text.IsDate(text))
            {
                this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
            }
            this.wherestr += "and DateDiff(dd,updateTime, @BeginDate)<=0 ";
            this.al.Add(this.conn.CreateParameter("@BeginDate", DbType.DateTime, text));
        }
        string text2 = this.TxtEndDate.Text;
        if (text2 != string.Empty)
        {
            if (!Text.IsDate(text2))
            {
                this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
            }
            if (text != string.Empty)
            {
                if (Convert.ToDateTime(text) > Convert.ToDateTime(text2))
                {
                    this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
                }
            }
            this.wherestr += "and DateDiff(dd,updateTime, @EndDate)>=0 ";
            this.al.Add(this.conn.CreateParameter("@EndDate", DbType.DateTime, text2));
        }
        string text3 = this.TxtUserName.Text.Trim();
        if (text3 != string.Empty)
        {
            this.wherestr += "and BuyerName like '%' + @cousmentName +'%'";
            this.al.Add(this.conn.CreateParameter("@cousmentName", DbType.String, text3.Trim()));
        }
        string selectedValue = this.DropMoment.SelectedValue;
        if (selectedValue != string.Empty)
        {
            string text4 = selectedValue;
            if (text4 != null)
            {
                if (!(text4 == "7"))
                {
                    if (!(text4 == "10"))
                    {
                        if (!(text4 == "30"))
                        {
                            if (text4 == "365")
                            {
                                this.wherestr += "and DateDiff(dd,UpdateTime,getdate())<=365";
                            }
                        }
                        else
                        {
                            this.wherestr += "and DateDiff(dd,UpdateTime, getdate())<=30 ";
                        }
                    }
                    else
                    {
                        this.wherestr += "and DateDiff(dd,UpdateTime, getdate())<=10 ";
                    }
                }
                else
                {
                    this.wherestr += "and DateDiff(dd,UpdateTime, getdate())<=7 ";
                }
            }
        }
        if (this.wherestr != string.Empty)
        {
            this.wherestr = "and" + this.wherestr;
            this.wherestr = this.wherestr.Replace("andand", "");
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.BindDate();
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        this.AddUserDropDownList();
    }
    protected void AddUserDropDownList()
    {
        if (this.TextBox1.Text != "")
        {
            IDbDataParameter dbDataParameter = this.conn.CreateParameter("@UserName", DbType.String, this.TextBox1.Text);
            IDataReader reader = this.conn.GetReader("Select UserID From [HL_User] Where ([UserName] = @UserName)", new IDbDataParameter[]
			{
				dbDataParameter
			});
            int num = 0;
            if (reader.Read())
            {
                num = Convert.ToInt32(reader["UserID"]);
                reader.Close();
                reader.Dispose();
                if (num != 0)
                {
                    foreach (ListItem listItem in this.DropDownList1.Items)
                    {
                        if (listItem.Text.Trim() == this.TextBox1.Text.Trim())
                        {
                            return;
                        }
                    }
                    ListItem item = new ListItem(this.TextBox1.Text, num.ToString());
                    this.DropDownList1.Items.Add(item);
                    this.DropDownList1.SelectedValue = num.ToString();
                }
            }
            else
            {
                reader.Close();
                reader.Dispose();
            }
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        this.BindDate();
    }
}
